<template>
  <Transition name="fade">
    <div v-if="visible" class="page-loading">
      <div class="page-loading__content">
        <div class="page-loading__spinner">
          <div class="spinner-ring"></div>
          <div class="spinner-ring"></div>
          <div class="spinner-ring"></div>
        </div>
        <p v-if="text" class="page-loading__text">{{ text }}</p>
      </div>
    </div>
  </Transition>
</template>

<script setup>
defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  text: {
    type: String,
    default: '加载中...'
  }
})
</script>

<style lang="scss" scoped>
.page-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  @include flex-center;
  z-index: 9999;
  
  &__content {
    text-align: center;
  }
  
  &__spinner {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto $spacing-lg;
  }
  
  &__text {
    color: white;
    font-size: $font-size-lg;
    font-weight: $font-weight-medium;
  }
}

.spinner-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border: 4px solid transparent;
  border-top-color: $primary-color;
  border-radius: 50%;
  animation: spin 1.5s cubic-bezier(0.5, 0, 0.5, 1) infinite;
  
  &:nth-child(1) {
    animation-delay: -0.45s;
  }
  
  &:nth-child(2) {
    animation-delay: -0.3s;
    border-top-color: $secondary-color;
  }
  
  &:nth-child(3) {
    animation-delay: -0.15s;
    border-top-color: $accent-color;
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>

